"use strict";
cc._RF.push(module, '02645fwJK1Lf6P9HaJSoTW3', 'level_peopleArcheryEnemy');
// scripts/levelBundles/level_PeopleArchery/unit/level_peopleArcheryEnemy.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../../engines/gameEngine");
var CsvFileKind_1 = require("../../../engines/libs/CsvFileKind");
var data_control_1 = require("../../../engines/libs/data_control");
var level_PeopleArcheryUnitBase_1 = require("../base/level_PeopleArcheryUnitBase");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_peopleArcheryEnemy = /** @class */ (function (_super) {
    __extends(level_peopleArcheryEnemy, _super);
    function level_peopleArcheryEnemy() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.lbHp = null;
        _this.roleSp = null;
        _this.shadowSp = null;
        _this.pedestalSp = null;
        _this.smallSps = [];
        _this.bigSps = [];
        _this.pedestalSps = [];
        _this.shadowSps = [];
        _this.hurtSp = null;
        _this.hurtSps = [];
        _this.hpNode = null;
        _this.hurtEffect = null;
        _this.xianSps = [];
        _this.moSps = [];
        _this.bossCloud = null;
        _this.normalCloud = null;
        _this.bossBg = null;
        _this.bossStar = null;
        _this.waveData = null;
        _this.lastWaveFlag = false;
        /**怪物类型 */
        _this.enemyType = 0;
        return _this;
    }
    Object.defineProperty(level_peopleArcheryEnemy.prototype, "hp", {
        /**获取当前血量 */
        get: function () { return this._hp; },
        /**设置当前血量 */
        set: function (hp) {
            hp = Math.floor(hp);
            this._hp = hp;
            this.lbHp.string = hp.toString();
        },
        enumerable: false,
        configurable: true
    });
    /**绑定类型  0是大怪 1是中怪 2是小怪 */
    level_peopleArcheryEnemy.prototype.bindType = function (type, lastWaveFlag, waveData) {
        this.enemyType = type;
        this.lastWaveFlag = lastWaveFlag;
        this.waveData = waveData;
        this.refrenshSize();
    };
    level_peopleArcheryEnemy.prototype.refrenshSize = function () {
        switch (this.enemyType) {
            case 0: {
                this.bossCloud.active = true;
                this.bossBg.active = true;
                this.bossStar.active = true;
                this.normalCloud.active = false;
                this.roleSp.spriteFrame = data_control_1.default.getRandItemOfArray(this.bigSps);
                this.pedestalSp.spriteFrame = this.pedestalSps[0];
                this.shadowSp.spriteFrame = this.shadowSps[0];
                var nCollider = this.node.getComponent(cc.BoxCollider);
                nCollider.size = cc.size(600, 150);
                this.hpNode.y = -100;
                break;
            }
            default: {
                if (this.enemyType == 1) {
                    this.pedestalSp.spriteFrame = this.pedestalSps[0];
                    var nCollider = this.node.getComponent(cc.BoxCollider);
                    nCollider.size = cc.size(600, 150);
                    this.hpNode.y = -100;
                    this.bossCloud.active = true;
                    this.bossBg.active = true;
                    this.bossStar.active = true;
                    this.normalCloud.active = false;
                }
                else {
                    this.pedestalSp.spriteFrame = this.pedestalSps[1];
                    this.roleSp.node.scale = this.roleSp.node.scale * 0.8;
                    // this.pedestalSp.node.scale = this.pedestalSp.node.scale * 0.8;
                    this.hurtSp.node.scale = this.hurtSp.node.scale * 0.8;
                    this.bossCloud.active = false;
                    this.normalCloud.active = true;
                    this.bossStar.active = false;
                    this.bossBg.active = false;
                }
                this.shadowSp.spriteFrame = this.shadowSps[1];
                this.roleSp.spriteFrame = this.smallSps[this.enemyType - 1];
                this.hurtSp.spriteFrame = this.hurtSps[this.enemyType - 1];
                this.hpNode.y = 20;
                break;
            }
        }
    };
    level_peopleArcheryEnemy.prototype.update = function (dt) {
        _super.prototype.update.call(this, dt);
        if (this.level.gamePauseFlag) {
            return;
        }
        var moveDis = this.level.getRoleMoveSpd() * dt;
        this.node.y -= moveDis;
        this.autoDeath();
    };
    level_peopleArcheryEnemy.prototype.unitBeHurt = function (atk, atkType, criticalFlag) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                if (!this.isDeath) {
                    this.level.damage += atk;
                    this.beHurtEffect();
                    return [2 /*return*/, _super.prototype.unitBeHurt.call(this, atk, atkType, criticalFlag)];
                }
                return [2 /*return*/];
            });
        });
    };
    level_peopleArcheryEnemy.prototype.beHurtEffect = function () {
        var randX = data_control_1.default.getRandNumberOfArrayTwo([-100, 100]);
        var randY = data_control_1.default.getRandNumberOfArrayTwo([0, 200]);
        var node = cc.instantiate(this.hurtEffect);
        node.active = true;
        node.setParent(this.node);
        node.setPosition(randX, randY);
        var roleProfile = this.level.role.profile;
        var spAry = [];
        switch (roleProfile) {
            case "0":
            case "1": {
                spAry = this.xianSps;
                break;
            }
            case "2": {
                spAry = this.moSps;
                break;
            }
        }
        var randSp = data_control_1.default.getRandItemOfArray(spAry);
        node.getComponent(cc.Sprite).spriteFrame = randSp;
        cc.tween(node).delay(0.2).to(0.5, { opacity: 0 }).call(function () {
            node.destroy();
            node.removeFromParent();
        }).start();
    };
    level_peopleArcheryEnemy.prototype.unitDeath = function () {
        return __awaiter(this, void 0, void 0, function () {
            var boxTypeId, boxdata, dropType, datas, i, drop, data, bossDeathRevitalizePercent, maxHp, addition, data, bossDeathRevitalizePercent, maxHp, addition, data;
            return __generator(this, function (_a) {
                switch (this.enemyType) {
                    case 0: {
                        gameEngine_1.default.getManagers().soundMgr.playSound("peopleArcherySound/Boss");
                        boxTypeId = this.waveData.boss_drop_type;
                        boxdata = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryBox, boxTypeId);
                        dropType = boxdata["drop_type"].split("&");
                        datas = [];
                        for (i = 0; i < dropType.length; i++) {
                            drop = dropType[i];
                            data = this.level.getOptions(drop, 1);
                            datas.push(data[0]);
                        }
                        // this.level.openBoxPage(datas,this.lastWaveFlag);
                        if (this.lastWaveFlag) {
                            // 打开获得修为界面
                            this.level.openMoneyPage();
                        }
                        else {
                            this.level.openRouGePage();
                        }
                        bossDeathRevitalizePercent = this.level.role.bossDeathRevitalizePercent;
                        if (bossDeathRevitalizePercent > 0) {
                            maxHp = this.level.role.maxHp;
                            addition = maxHp * bossDeathRevitalizePercent;
                            data = { param_type: "0", option_param: addition, reCoverMaxHp: "0" };
                            this.level.parseDataAddPeople(data);
                        }
                        this.level.role.showTitle("2");
                        break;
                    }
                    case 1: {
                        this.level.openRouGePage();
                        bossDeathRevitalizePercent = this.level.role.bossDeathRevitalizePercent;
                        if (bossDeathRevitalizePercent > 0) {
                            maxHp = this.level.role.maxHp;
                            addition = maxHp * bossDeathRevitalizePercent;
                            data = { param_type: "0", option_param: addition, reCoverMaxHp: "0" };
                            this.level.parseDataAddPeople(data);
                        }
                        break;
                    }
                    default: {
                        this.level.createOneBox(this);
                        break;
                    }
                }
                this.level.killCount++;
                this.level.killOneEnemy(this.enemyType);
                _super.prototype.unitDeath.call(this);
                return [2 /*return*/];
            });
        });
    };
    level_peopleArcheryEnemy.prototype.unitBeHurtAni = function () {
        return __awaiter(this, void 0, void 0, function () {
            var width, once;
            return __generator(this, function (_a) {
                width = 4;
                cc.Tween.stopAllByTarget(this.roleSp.node);
                this.roleSp.node.x = 0;
                this.roleSp.node.y = 15;
                once = cc.tween(this.roleSp.node)
                    .by(0.02, { x: width, y: width })
                    .by(0.02, { x: 0, y: -width })
                    .by(0.02, { x: -width, y: -width })
                    .by(0.02, { x: -width, y: 0 })
                    .by(0.02, { x: 0, y: width })
                    .by(0.02, { x: width, y: 0 });
                cc.tween(this.roleSp.node)
                    .then(once)
                    .start();
                return [2 /*return*/];
            });
        });
    };
    level_peopleArcheryEnemy.prototype.redSharkAni = function () {
        var _this = this;
        cc.Tween.stopAllByTarget(this.hurtSp.node);
        this.hurtSp.node.active = true;
        cc.tween(this.hurtSp.node)
            .delay(0.2)
            .call(function () {
            _this.hurtSp.node.active = false;
        })
            .start();
    };
    __decorate([
        property({ type: cc.Label, tooltip: "血量文本" })
    ], level_peopleArcheryEnemy.prototype, "lbHp", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "角色图标" })
    ], level_peopleArcheryEnemy.prototype, "roleSp", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "影子图标" })
    ], level_peopleArcheryEnemy.prototype, "shadowSp", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "底座图标" })
    ], level_peopleArcheryEnemy.prototype, "pedestalSp", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "小怪图片" })
    ], level_peopleArcheryEnemy.prototype, "smallSps", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "大怪图片" })
    ], level_peopleArcheryEnemy.prototype, "bigSps", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "底座图片" })
    ], level_peopleArcheryEnemy.prototype, "pedestalSps", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "影子图片" })
    ], level_peopleArcheryEnemy.prototype, "shadowSps", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "受伤图片" })
    ], level_peopleArcheryEnemy.prototype, "hurtSp", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "受伤图片" })
    ], level_peopleArcheryEnemy.prototype, "hurtSps", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "血量节点" })
    ], level_peopleArcheryEnemy.prototype, "hpNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "受击节点" })
    ], level_peopleArcheryEnemy.prototype, "hurtEffect", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "仙的受击" })
    ], level_peopleArcheryEnemy.prototype, "xianSps", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "魔的受击" })
    ], level_peopleArcheryEnemy.prototype, "moSps", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "boss的云" })
    ], level_peopleArcheryEnemy.prototype, "bossCloud", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "普通的云" })
    ], level_peopleArcheryEnemy.prototype, "normalCloud", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "boss背景" })
    ], level_peopleArcheryEnemy.prototype, "bossBg", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "boss星星" })
    ], level_peopleArcheryEnemy.prototype, "bossStar", void 0);
    level_peopleArcheryEnemy = __decorate([
        ccclass
    ], level_peopleArcheryEnemy);
    return level_peopleArcheryEnemy;
}(level_PeopleArcheryUnitBase_1.default));
exports.default = level_peopleArcheryEnemy;

cc._RF.pop();